package by.epam.trenings.vkphotorest.content.database;

import com.google.gson.Gson;

import by.epam.trenings.vkphotorest.content.bo.PhotoModel;
import by.epam.trenings.vkphotorest.content.contract.TaskContract;
import android.content.ContentValues;

public class PhotosTable {

	public PhotosTable() {

	}

	/** The Constant COOKIE_TABLE. */
	public static final String PHOTOS_TABLE = "PHOTOS";

	/** The Constant COOKIE_COLUMNS. */
	public static final String[] PHOTOS_COLUMNS = {
			TaskContract.PhotosColumns.PHOTO_ID,
			TaskContract.PhotosColumns.CREATED,
			TaskContract.PhotosColumns.SERVER_ID,
			TaskContract.PhotosColumns.OWNER_ID,
			TaskContract.PhotosColumns.PID, TaskContract.PhotosColumns.SRC,
			TaskContract.PhotosColumns.SRC_BIG,
			TaskContract.PhotosColumns.SRC_SMALL,
			TaskContract.PhotosColumns.DISCRIPTION };

	/** The Constant PHOTO_ID_COL_INDEX. */
	public static final int PHOTO_ID_COL_INDEX = 0;

	/** The Constant SERVER_ID_COL_INDEX. */
	public static final int ALBUM_ID_COL_INDEX = 1;

	/** The Constant CREATED_COL_INDEX. */
	public static final int CREATED_COL_INDEX = 2;

	/** The Constant OWNER_ID_COL_INDEX. */
	public static final int OWNER_ID_COL_INDEX = 3;

	/** The Constant PID_COL_INDEX. */
	public static final int PID_COL_INDEX = 4;

	/** The Constant SRC_COL_INDEX. */
	public static final int SRC_COL_INDEX = 5;

	/** The Constant SRC_BIG_COL_INDEX. */
	public static final int SRC_BIG_COL_INDEX = 6;

	/** The Constant SRC_SMALL_COL_INDEX. */
	public static final int SRC_SMALL_COL_INDEX = 7;

	/** The Constant TEXT_COL_INDEX. */
	public static final int TEXT_COL_INDEX = 8;

	/** The Constant CREATE_COOKIE_TABLE_SQL. */
	public static final String CREATE_PHOTOS_TABLE_SQL = "CREATE TABLE "
			+ PHOTOS_TABLE + " (" + PHOTOS_COLUMNS[PHOTO_ID_COL_INDEX]
			+ " INTEGER PRIMARY KEY AUTOINCREMENT, "
			+ PHOTOS_COLUMNS[ALBUM_ID_COL_INDEX] + " INTEGER, "
			+ PHOTOS_COLUMNS[CREATED_COL_INDEX] + " INTEGER, "
			+ PHOTOS_COLUMNS[OWNER_ID_COL_INDEX] + " INTEGER, "
			+ PHOTOS_COLUMNS[PID_COL_INDEX] + " INTEGER, "
			+ PHOTOS_COLUMNS[SRC_COL_INDEX] + " TEXT, "
			+ PHOTOS_COLUMNS[SRC_BIG_COL_INDEX] + " TEXT, "
			+ PHOTOS_COLUMNS[SRC_SMALL_COL_INDEX] + " TEXT, "
			+ PHOTOS_COLUMNS[TEXT_COL_INDEX] + " TEXT)";

	/** The Constant DROP_COOKIE_TABLE_SQL. */
	public static final String DROP_PHOTOS_TABLE_SQL = "DROP TABLE IF EXISTS "
			+ PHOTOS_TABLE;

	public static ContentValues getContentValues(String photo) {
		PhotoModel photoDeserialised = new Gson().fromJson(photo,
				PhotoModel.class);
		ContentValues values = new ContentValues();
		values.put(PHOTOS_COLUMNS[PhotosTable.CREATED_COL_INDEX],
				photoDeserialised.getCreated());
		values.put(PHOTOS_COLUMNS[PhotosTable.ALBUM_ID_COL_INDEX],
				photoDeserialised.getAlbumId());
		values.put(PHOTOS_COLUMNS[PhotosTable.OWNER_ID_COL_INDEX],
				photoDeserialised.getOwnerId());
		values.put(PHOTOS_COLUMNS[PhotosTable.PID_COL_INDEX],
				photoDeserialised.getPid());
		values.put(PHOTOS_COLUMNS[PhotosTable.SRC_BIG_COL_INDEX],
				photoDeserialised.getSrcBig());
		values.put(PHOTOS_COLUMNS[PhotosTable.SRC_COL_INDEX],
				photoDeserialised.getSrc());
		values.put(PHOTOS_COLUMNS[PhotosTable.SRC_SMALL_COL_INDEX],
				photoDeserialised.getSrcSmall());
		values.put(PHOTOS_COLUMNS[PhotosTable.TEXT_COL_INDEX],
				photoDeserialised.getText());
		return values;
	}

}
